package com.programs.waw;

import java.util.List;

import android.content.Context;
import android.graphics.Color;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.TextView;

public class AliceAdapter extends ArrayAdapter<AliceData> {

	private int resource;
	private LayoutInflater inflater;
	private String ssid;

	public AliceAdapter(Context context, int resourceId,
			List<AliceData> objects, String ssid) {
		super(context, resourceId, objects);
		resource = resourceId;
		inflater = LayoutInflater.from(context);
		this.ssid = ssid;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {

		AliceData a = getItem(position);

		AliceViewCache aliceViewCache;

		if (convertView == null) {
			convertView = inflater.inflate(resource, null);
			aliceViewCache = new AliceViewCache(convertView);
			convertView.setTag(aliceViewCache);
		} else {
			aliceViewCache = (AliceViewCache) convertView.getTag();
		}

		TextView wpaResult = aliceViewCache.getTextViewWpa();
		wpaResult.setText(a.getWpa());

		TextView ssidResult = aliceViewCache.getTextViewSsid();
		ssidResult.setText(a.getSsid());

		if (!ssid.startsWith(a.getSsid())) {
			ssidResult.setTextColor(Color.parseColor("#FF6103"));
		} else {
			ssidResult.setTextColor(Color.parseColor("#09F911"));
		}

		return convertView;
	}

}
